package com.etoak.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


/**
 * 交换机  fanout、direct、topic、headers
 * Spring API  FanoutExchange、DirectExchange、TopicExchange、CustomExchange
 * param.put("x-delayed-type", "direct")
 * x-delayed-message
 */
@Configuration
public class OrderQueueConfig {

    public static final String EXCHANGE="amqp.order";

    public static final String QUEUE="order";

    public static final String KEY="order";

    @Bean
    public Queue orderQueue() {
        return new Queue(QUEUE);
    }

    @Bean
    public CustomExchange orderExchange() {
        Map<String,Object> param = new HashMap<>();
        param.put("x-delayed-type", "direct");

        return new CustomExchange(EXCHANGE,"x-delayed-message",true,false,param);
    }

    @Bean
    public Binding orderBinding(Queue orderQueue,CustomExchange orderExchange) {
        return BindingBuilder.bind(orderQueue).to(orderExchange).with(KEY).noargs();
    }

}
